package com.itheima.question.timer;

import com.itheima.common.contants.RedisPicConstans;
import com.itheima.question.config.FastDFSClientUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Set;

@Component
@Slf4j
public class TaskDemo {
    @Autowired
    private FastDFSClientUtil fastDFSClientUtil;
    @Autowired
    private RedisTemplate redisTemplate;

    @Scheduled(cron = "0/5 * * * * ?")
    public void clearPoc(){
        Set<String> pics = redisTemplate.opsForSet().difference(RedisPicConstans.ALL_PIC,RedisPicConstans.USE_PIC);
        log.info("定时任务开始执行，需要清理的图片有：" + pics);
        for(String pic : pics){
            fastDFSClientUtil.delFile(pic);
        }
        System.out.println("hello spring task" + new Date());
    }
}
